<template>
    <div class="like">
      <div class="title">{{title}}</div>
      <div class="list" >
        <div class="item" v-for="(item,index) in list" :key="index" @click="checkDetail(item)">
          <div class="cover" :title="item.movie_name"><el-image :src="item.img" lazy></el-image></div>
          <div class="name":title="item.movie_name">{{item.title}}</div>
          <div class="role">{{item.to_star}}</div>
        </div>
      </div>
    </div>
</template>

<script>
  import {getLikeList} from '@/api/movieList'

  export default {
    name: 'Like',
    data(){
      return{
        title: '猜你喜欢',
        list:[],
        loading: true
      }
    },
    created() {
      this.fetchData()
    },
    methods:{
      fetchData(){
        getLikeList().then(response => {
          let data = response.data
          this.list = data
          this.loading = false
        })
      },
      checkDetail(item){
        let routeUrl = this.$router.resolve({
          path: '/detail',
          query: {id:item.source_id}
        });
        window.open(routeUrl .href, '_blank');
        //this.$router.push({path:'/detail',query:{id:item.source_id}})
      }
    }
  }
</script>

<style lang="scss" scoped>
.like{
  margin-bottom: 10px;
  .title{
    margin-top: 10px;
    padding: 0 10px;
    line-height: 30px;
    color: #373737;
    font-size: 16px;
    background: #f9f9f9;
    border: 1px solid #F0F0F0;
  }
  .list{
    height: 454px;
    border: 1px solid #F0F0F0;
    display: flex;
    flex-wrap: wrap;
    .item{
      margin: 10px 9px;
      width: 120px;
      text-align: center;
      &:hover{
        .el-image{
          transform: scale(1.2);
          transition: all 1s;
        }
        .name{
          color: #00C064;
        }
      }
      .cover{
        width: 100%;
        height: 165px;
        overflow: hidden;
        cursor: pointer;
        .el-image{
          width: 100%;
          height: 100%;
        }
      }
      .name{
        margin-top: 5px;
        color: #333;
        cursor: pointer;
        display: -webkit-box;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
      }
      .role{
        margin-top: 5px;
        color: #737373;
        display: -webkit-box;
        overflow: hidden;
        text-overflow: ellipsis;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
      }
    }
  }
}
</style>
